module Oos4ruby
  class Media < Bean::BeanClass
    include Bean
    
    define_el_reader AtomNamespace => [:title, :updated, :content]
    define_attr_reader AtomNamespace => {:content => :type, :content => :src}
    
    attr_writer :title
    
    def initialize(entry, auth, slug = nil)
      @xml = entry
      @auth = auth
      @slug = slug || @xml.child('slug', OosNamespace).text      
    end
    
    def Media.dump!(opts, slug)
      file = opts.delete(:file)
      file.respond_to?(:path) ? file : File.new(file)
    end
    
    private
    def load!
      @xml.child('title').text = @title if @title      
    end    
  end
end
